﻿@{
    if (!IsPost) {
        Response.Redirect("~/Products");
    }

    var db = Database.Open("bakery");
    var productId = Request["ProductId"];
    var product = db.QuerySingle("SELECT * FROM Products WHERE ID = @0", productId);

    var orderShipping = Request["orderShipping"];
    var customerEmail = Request["orderEmail"];
    
    var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped) + Request.ApplicationPath;
    var cancelUrl = hostUrl + "Products";
    var returnUrl = hostUrl + "Success";
    
    // Enter the email of the receiver 
    var receiver = ""; 
    
    var amount = product.Price * Request["orderQty"].AsDecimal();
    var sender = customerEmail;
    
    var response = PayPal.AdaptivePayments.SimplePay.Execute
                    (receiver, amount, sender, "WebMatrix Integration", "127.0.0.1", "Test Device", cancelUrl, returnUrl);  
    
    response.Redirect();
}
